package Linux五种IO模型;


import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;

/**
 * @author coderFu
 * @create 2022/3/5
 * 文件channel 通道 信息传输
 */
public class FileChannelDemo {

    public static void main(String[] args) throws IOException {

        RandomAccessFile fromFile = new RandomAccessFile("china.txt","rw");

        RandomAccessFile toFile = new RandomAccessFile("china2.txt", "rw");

        FileChannel fromFileChannel = fromFile.getChannel();

        FileChannel toFileChannel = toFile.getChannel();

        long  position = 0;
        long count = fromFileChannel.size();

        // 获取当前文件的位置
        long position1 = toFileChannel.position();
        toFileChannel.position(position1+1);
        long targetPosition = toFileChannel.size();
        // 会覆盖
//        toFileChannel.transferFrom(fromFileChannel,position,count);
        fromFileChannel.transferTo(position,count,toFileChannel);
        toFileChannel.truncate(3);
        fromFileChannel.truncate(10);





    }




}
